﻿#include "StdAfx.h"
//#include "io.h"
#include "stdio.h"
#include "stdlib.h"
#include "locale.h"
#include "LogHelper.h"
#include "SplitDemo.h"
#include "atlenc.h"
#define LOG_FILE_NAME     _T("Log.log")

CLogHelper::CLogHelper(void)
{
}

CLogHelper::~CLogHelper(void)
{
}


int CLogHelper::WriteLog0(LPCTSTR swzCur, LPCTSTR lpszLog)
{
	// 获取日志文件路径

	static CString strLogFilePath;
	strLogFilePath.Format(L"%s", swzCur);
	if (strLogFilePath.IsEmpty())
	{
		strLogFilePath = MakeFilePath();
	}
	// 判断日志文件是否存在，不存在则创建
	wchar_t* pwchLogFilePath = strLogFilePath.AllocSysString();
	errno_t err = 0;
	if ((err = _taccess_s(pwchLogFilePath, 0)) != 0)
	{
		CFile file;
		if (file.Open(strLogFilePath, CFile::modeCreate | CFile::typeBinary | CFile::modeWrite))
		{
			const unsigned char LeadBytes[] = { 0xEF, 0xBB, 0xBF };
			file.Write(LeadBytes, sizeof(LeadBytes));
			file.Close();
		}


	}
	SysFreeString(pwchLogFilePath);
	// 向日志文件写入日志
	CStdioFile file;
	if (file.Open((LPCTSTR)strLogFilePath, CFile::modeWrite | CFile::typeBinary | CFile::shareDenyNone))
		//	if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite ))
	{
		//  CString strMsg = MakeLogMsg(lpszLog);
		//CString strMsg = lpszLog;
		file.SeekToEnd();
		char* old_locale = _strdup(setlocale(LC_CTYPE, NULL));
		setlocale(LC_CTYPE, "chs");// 设定区域

		int nSrcLen = (int)wcslen(lpszLog);//content为要写入的文本
		CStringA utf8String(lpszLog);
		utf8String += L"\r\n";
		int nBufLen = (nSrcLen + 1) * 6;
		LPSTR buffer = utf8String.GetBufferSetLength(nBufLen);
		int nLen = AtlUnicodeToUTF8(lpszLog, nSrcLen, buffer, nBufLen);
		//上面的函数AtlUnicodeToUTF8()需头文件：<atlenc.h>
		//功能：将unicode转换成utf-8
		buffer[nLen] = 0;
		utf8String.ReleaseBuffer();

		file.Write(utf8String.GetBuffer(), nLen);

		setlocale(LC_CTYPE, old_locale);
		if (old_locale)free(old_locale);//还原区域设定
		file.Close();
		return 0;
	}
	return -1;
}
int CLogHelper::WriteLog1(LPCTSTR swzCur, LPCTSTR lpszLog)
{
	// 获取日志文件路径

	static CString strLogFilePath;
	strLogFilePath.Format(L"%s", swzCur);
	if (strLogFilePath.IsEmpty())
	{
		strLogFilePath = MakeFilePath();
	}
	// 判断日志文件是否存在，不存在则创建
	wchar_t* pwchLogFilePath = strLogFilePath.AllocSysString();
	errno_t err = 0;
	if ((err = _taccess_s(pwchLogFilePath, 0)) != 0)
	{
		CFile file;
		if (file.Open(strLogFilePath, CFile::modeCreate | CFile::typeBinary | CFile::modeWrite))
		{
			const unsigned char LeadBytes[] = { 0xEF, 0xBB, 0xBF };
			file.Write(LeadBytes, sizeof(LeadBytes));
			file.Close();
		}


	}
	SysFreeString(pwchLogFilePath);
	// 向日志文件写入日志
	CStdioFile file;
	if (file.Open((LPCTSTR)strLogFilePath, CFile::modeWrite | CFile::typeBinary | CFile::shareDenyNone))
		//	if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite ))
	{
		//  CString strMsg = MakeLogMsg(lpszLog);
		//CString strMsg = lpszLog;
		file.SeekToEnd();
		char* old_locale = _strdup(setlocale(LC_CTYPE, NULL));
		setlocale(LC_CTYPE, "chs");// 设定区域

		int nSrcLen = (int)wcslen(lpszLog);//content为要写入的文本
		CStringA utf8String(lpszLog);
		utf8String += L"\r\n";
		int nBufLen = (nSrcLen + 1) * 6;
		LPSTR buffer = utf8String.GetBufferSetLength(nBufLen);
		int nLen = AtlUnicodeToUTF8(lpszLog, nSrcLen, buffer, nBufLen);
		//上面的函数AtlUnicodeToUTF8()需头文件：<atlenc.h>
		//功能：将unicode转换成utf-8
		buffer[nLen] = 0;
		utf8String.ReleaseBuffer();

		file.Write(utf8String.GetBuffer(), nLen);

		setlocale(LC_CTYPE, old_locale);
		if (old_locale)free(old_locale);//还原区域设定
		file.Close();
		return 0;
	}
	return -1;
}
int CLogHelper::WriteLog2(LPCTSTR swzCur, LPCTSTR lpszLog)
{
	// 获取日志文件路径

	static CString strLogFilePath;
	strLogFilePath.Format(L"%s", swzCur);
	if (strLogFilePath.IsEmpty())
	{
		strLogFilePath = MakeFilePath();
	}
	// 判断日志文件是否存在，不存在则创建
	wchar_t* pwchLogFilePath = strLogFilePath.AllocSysString();
	errno_t err = 0;
	if ((err = _taccess_s(pwchLogFilePath, 0)) != 0)
	{
		CFile file;
		if (file.Open(strLogFilePath, CFile::modeCreate | CFile::typeBinary | CFile::modeWrite))
		{
			const unsigned char LeadBytes[] = { 0xEF, 0xBB, 0xBF };
			file.Write(LeadBytes, sizeof(LeadBytes));
			file.Close();
		}


	}
	SysFreeString(pwchLogFilePath);
	// 向日志文件写入日志
	CStdioFile file;
	if (file.Open((LPCTSTR)strLogFilePath, CFile::modeWrite | CFile::typeBinary | CFile::shareDenyNone))
		//	if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite ))
	{
		//  CString strMsg = MakeLogMsg(lpszLog);
		//CString strMsg = lpszLog;
		file.SeekToEnd();
		char* old_locale = _strdup(setlocale(LC_CTYPE, NULL));
		setlocale(LC_CTYPE, "chs");// 设定区域

		int nSrcLen = (int)wcslen(lpszLog);//content为要写入的文本
		CStringA utf8String(lpszLog);
		utf8String += L"\r\n";
		int nBufLen = (nSrcLen + 1) * 6;
		LPSTR buffer = utf8String.GetBufferSetLength(nBufLen);
		int nLen = AtlUnicodeToUTF8(lpszLog, nSrcLen, buffer, nBufLen);
		//上面的函数AtlUnicodeToUTF8()需头文件：<atlenc.h>
		//功能：将unicode转换成utf-8
		buffer[nLen] = 0;
		utf8String.ReleaseBuffer();

		file.Write(utf8String.GetBuffer(), nLen);

		setlocale(LC_CTYPE, old_locale);
		if (old_locale)free(old_locale);//还原区域设定
		file.Close();
		return 0;
	}
	return -1;
}
int CLogHelper::WriteLog3(LPCTSTR swzCur, LPCTSTR lpszLog)
{
	// 获取日志文件路径

	static CString strLogFilePath;
	strLogFilePath.Format(L"%s", swzCur);
	if (strLogFilePath.IsEmpty())
	{
		strLogFilePath = MakeFilePath();
	}
	// 判断日志文件是否存在，不存在则创建
	wchar_t* pwchLogFilePath = strLogFilePath.AllocSysString();
	errno_t err = 0;
	if ((err = _taccess_s(pwchLogFilePath, 0)) != 0)
	{
		CFile file;
		if (file.Open(strLogFilePath, CFile::modeCreate | CFile::typeBinary | CFile::modeWrite))
		{
			const unsigned char LeadBytes[] = { 0xEF, 0xBB, 0xBF };
			file.Write(LeadBytes, sizeof(LeadBytes));
			file.Close();
		}


	}
	SysFreeString(pwchLogFilePath);
	// 向日志文件写入日志
	CStdioFile file;
	if (file.Open((LPCTSTR)strLogFilePath, CFile::modeWrite | CFile::typeBinary | CFile::shareDenyNone))
		//	if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite ))
	{
		//  CString strMsg = MakeLogMsg(lpszLog);
		//CString strMsg = lpszLog;
		file.SeekToEnd();
		char* old_locale = _strdup(setlocale(LC_CTYPE, NULL));
		setlocale(LC_CTYPE, "chs");// 设定区域

		int nSrcLen = (int)wcslen(lpszLog);//content为要写入的文本
		CStringA utf8String(lpszLog);
		utf8String += L"\r\n";
		int nBufLen = (nSrcLen + 1) * 6;
		LPSTR buffer = utf8String.GetBufferSetLength(nBufLen);
		int nLen = AtlUnicodeToUTF8(lpszLog, nSrcLen, buffer, nBufLen);
		//上面的函数AtlUnicodeToUTF8()需头文件：<atlenc.h>
		//功能：将unicode转换成utf-8
		buffer[nLen] = 0;
		utf8String.ReleaseBuffer();

		file.Write(utf8String.GetBuffer(), nLen);

		setlocale(LC_CTYPE, old_locale);
		if (old_locale)free(old_locale);//还原区域设定
		file.Close();
		return 0;
	}
	return -1;
}
int CLogHelper::WriteLog4(LPCTSTR swzCur, LPCTSTR lpszLog)
{
	// 获取日志文件路径

	static CString strLogFilePath;
	strLogFilePath.Format(L"%s", swzCur);
	if (strLogFilePath.IsEmpty())
	{
		strLogFilePath = MakeFilePath();
	}
	// 判断日志文件是否存在，不存在则创建
	wchar_t* pwchLogFilePath = strLogFilePath.AllocSysString();
	errno_t err = 0;
	if ((err = _taccess_s(pwchLogFilePath, 0)) != 0)
	{
		CFile file;
		if (file.Open(strLogFilePath, CFile::modeCreate | CFile::typeBinary | CFile::modeWrite))
		{
			const unsigned char LeadBytes[] = { 0xEF, 0xBB, 0xBF };
			file.Write(LeadBytes, sizeof(LeadBytes));
			file.Close();
		}


	}
	SysFreeString(pwchLogFilePath);
	// 向日志文件写入日志
	CStdioFile file;
	if (file.Open((LPCTSTR)strLogFilePath, CFile::modeWrite | CFile::typeBinary | CFile::shareDenyNone))
		//	if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite ))
	{
		//  CString strMsg = MakeLogMsg(lpszLog);
		//CString strMsg = lpszLog;
		file.SeekToEnd();
		char* old_locale = _strdup(setlocale(LC_CTYPE, NULL));
		setlocale(LC_CTYPE, "chs");// 设定区域

		int nSrcLen = (int)wcslen(lpszLog);//content为要写入的文本
		CStringA utf8String(lpszLog);
		utf8String += L"\r\n";
		int nBufLen = (nSrcLen + 1) * 6;
		LPSTR buffer = utf8String.GetBufferSetLength(nBufLen);
		int nLen = AtlUnicodeToUTF8(lpszLog, nSrcLen, buffer, nBufLen);
		//上面的函数AtlUnicodeToUTF8()需头文件：<atlenc.h>
		//功能：将unicode转换成utf-8
		buffer[nLen] = 0;
		utf8String.ReleaseBuffer();

		file.Write(utf8String.GetBuffer(), nLen);

		setlocale(LC_CTYPE, old_locale);
		if (old_locale)free(old_locale);//还原区域设定
		file.Close();
		return 0;
	}
	return -1;
}
int CLogHelper::WriteLog5(LPCTSTR swzCur, LPCTSTR lpszLog)
{
	// 获取日志文件路径

	static CString strLogFilePath;
	strLogFilePath.Format(L"%s", swzCur);
	if (strLogFilePath.IsEmpty())
	{
		strLogFilePath = MakeFilePath();
	}
	// 判断日志文件是否存在，不存在则创建
	wchar_t* pwchLogFilePath = strLogFilePath.AllocSysString();
	errno_t err = 0;
	if ((err = _taccess_s(pwchLogFilePath, 0)) != 0)
	{
		CFile file;
		if (file.Open(strLogFilePath, CFile::modeCreate | CFile::typeBinary | CFile::modeWrite))
		{
			const unsigned char LeadBytes[] = { 0xEF, 0xBB, 0xBF };
			file.Write(LeadBytes, sizeof(LeadBytes));
			file.Close();
		}


	}
	SysFreeString(pwchLogFilePath);
	// 向日志文件写入日志
	CStdioFile file;
	if (file.Open((LPCTSTR)strLogFilePath, CFile::modeWrite | CFile::typeBinary | CFile::shareDenyNone))
		//	if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite ))
	{
		//  CString strMsg = MakeLogMsg(lpszLog);
		//CString strMsg = lpszLog;
		file.SeekToEnd();
		char* old_locale = _strdup(setlocale(LC_CTYPE, NULL));
		setlocale(LC_CTYPE, "chs");// 设定区域

		int nSrcLen = (int)wcslen(lpszLog);//content为要写入的文本
		CStringA utf8String(lpszLog);
		utf8String += L"\r\n";
		int nBufLen = (nSrcLen + 1) * 6;
		LPSTR buffer = utf8String.GetBufferSetLength(nBufLen);
		int nLen = AtlUnicodeToUTF8(lpszLog, nSrcLen, buffer, nBufLen);
		//上面的函数AtlUnicodeToUTF8()需头文件：<atlenc.h>
		//功能：将unicode转换成utf-8
		buffer[nLen] = 0;
		utf8String.ReleaseBuffer();

		file.Write(utf8String.GetBuffer(), nLen);

		setlocale(LC_CTYPE, old_locale);
		if (old_locale)free(old_locale);//还原区域设定
		file.Close();
		return 0;
	}
	return -1;
}
int CLogHelper::WriteLog6(LPCTSTR swzCur, LPCTSTR lpszLog)
{
	// 获取日志文件路径

	static CString strLogFilePath;
	strLogFilePath.Format(L"%s", swzCur);
	if (strLogFilePath.IsEmpty())
	{
		strLogFilePath = MakeFilePath();
	}
	// 判断日志文件是否存在，不存在则创建
	wchar_t* pwchLogFilePath = strLogFilePath.AllocSysString();
	errno_t err = 0;
	if ((err = _taccess_s(pwchLogFilePath, 0)) != 0)
	{
		CFile file;
		if (file.Open(strLogFilePath, CFile::modeCreate | CFile::typeBinary | CFile::modeWrite))
		{
			const unsigned char LeadBytes[] = { 0xEF, 0xBB, 0xBF };
			file.Write(LeadBytes, sizeof(LeadBytes));
			file.Close();
		}


	}
	SysFreeString(pwchLogFilePath);
	// 向日志文件写入日志
	CStdioFile file;
	if (file.Open((LPCTSTR)strLogFilePath, CFile::modeWrite | CFile::typeBinary | CFile::shareDenyNone))
		//	if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite ))
	{
		//  CString strMsg = MakeLogMsg(lpszLog);
		//CString strMsg = lpszLog;
		file.SeekToEnd();
		char* old_locale = _strdup(setlocale(LC_CTYPE, NULL));
		setlocale(LC_CTYPE, "chs");// 设定区域

		int nSrcLen = (int)wcslen(lpszLog);//content为要写入的文本
		CStringA utf8String(lpszLog);
		utf8String += L"\r\n";
		int nBufLen = (nSrcLen + 1) * 6;
		LPSTR buffer = utf8String.GetBufferSetLength(nBufLen);
		int nLen = AtlUnicodeToUTF8(lpszLog, nSrcLen, buffer, nBufLen);
		//上面的函数AtlUnicodeToUTF8()需头文件：<atlenc.h>
		//功能：将unicode转换成utf-8
		buffer[nLen] = 0;
		utf8String.ReleaseBuffer();

		file.Write(utf8String.GetBuffer(), nLen);

		setlocale(LC_CTYPE, old_locale);
		if (old_locale)free(old_locale);//还原区域设定
		file.Close();
		return 0;
	}
	return -1;
}
int CLogHelper::WriteLog7(LPCTSTR swzCur, LPCTSTR lpszLog)
{
	// 获取日志文件路径

	static CString strLogFilePath;
	strLogFilePath.Format(L"%s", swzCur);
	if (strLogFilePath.IsEmpty())
	{
		strLogFilePath = MakeFilePath();
	}
	// 判断日志文件是否存在，不存在则创建
	wchar_t* pwchLogFilePath = strLogFilePath.AllocSysString();
	errno_t err = 0;
	if ((err = _taccess_s(pwchLogFilePath, 0)) != 0)
	{
		CFile file;
		if (file.Open(strLogFilePath, CFile::modeCreate | CFile::typeBinary | CFile::modeWrite))
		{
			const unsigned char LeadBytes[] = { 0xEF, 0xBB, 0xBF };
			file.Write(LeadBytes, sizeof(LeadBytes));
			file.Close();
		}


	}
	SysFreeString(pwchLogFilePath);
	// 向日志文件写入日志
	CStdioFile file;
	if (file.Open((LPCTSTR)strLogFilePath, CFile::modeWrite | CFile::typeBinary | CFile::shareDenyNone))
		//	if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite ))
	{
		//  CString strMsg = MakeLogMsg(lpszLog);
		//CString strMsg = lpszLog;
		file.SeekToEnd();
		char* old_locale = _strdup(setlocale(LC_CTYPE, NULL));
		setlocale(LC_CTYPE, "chs");// 设定区域

		int nSrcLen = (int)wcslen(lpszLog);//content为要写入的文本
		CStringA utf8String(lpszLog);
		utf8String += L"\r\n";
		int nBufLen = (nSrcLen + 1) * 6;
		LPSTR buffer = utf8String.GetBufferSetLength(nBufLen);
		int nLen = AtlUnicodeToUTF8(lpszLog, nSrcLen, buffer, nBufLen);
		//上面的函数AtlUnicodeToUTF8()需头文件：<atlenc.h>
		//功能：将unicode转换成utf-8
		buffer[nLen] = 0;
		utf8String.ReleaseBuffer();

		file.Write(utf8String.GetBuffer(), nLen);

		setlocale(LC_CTYPE, old_locale);
		if (old_locale)free(old_locale);//还原区域设定
		file.Close();
		return 0;
	}
	return -1;
}
int CLogHelper::WriteLog8(LPCTSTR swzCur, LPCTSTR lpszLog)
{
	// 获取日志文件路径

	static CString strLogFilePath;
	strLogFilePath.Format(L"%s", swzCur);
	if (strLogFilePath.IsEmpty())
	{
		strLogFilePath = MakeFilePath();
	}
	// 判断日志文件是否存在，不存在则创建
	wchar_t* pwchLogFilePath = strLogFilePath.AllocSysString();
	errno_t err = 0;
	if ((err = _taccess_s(pwchLogFilePath, 0)) != 0)
	{
		CFile file;
		if (file.Open(strLogFilePath, CFile::modeCreate | CFile::typeBinary | CFile::modeWrite))
		{
			const unsigned char LeadBytes[] = { 0xEF, 0xBB, 0xBF };
			file.Write(LeadBytes, sizeof(LeadBytes));
			file.Close();
		}


	}
	SysFreeString(pwchLogFilePath);
	// 向日志文件写入日志
	CStdioFile file;
	if (file.Open((LPCTSTR)strLogFilePath, CFile::modeWrite | CFile::typeBinary | CFile::shareDenyNone))
		//	if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite ))
	{
		//  CString strMsg = MakeLogMsg(lpszLog);
		//CString strMsg = lpszLog;
		file.SeekToEnd();
		char* old_locale = _strdup(setlocale(LC_CTYPE, NULL));
		setlocale(LC_CTYPE, "chs");// 设定区域

		int nSrcLen = (int)wcslen(lpszLog);//content为要写入的文本
		CStringA utf8String(lpszLog);
		utf8String += L"\r\n";
		int nBufLen = (nSrcLen + 1) * 6;
		LPSTR buffer = utf8String.GetBufferSetLength(nBufLen);
		int nLen = AtlUnicodeToUTF8(lpszLog, nSrcLen, buffer, nBufLen);
		//上面的函数AtlUnicodeToUTF8()需头文件：<atlenc.h>
		//功能：将unicode转换成utf-8
		buffer[nLen] = 0;
		utf8String.ReleaseBuffer();

		file.Write(utf8String.GetBuffer(), nLen);

		setlocale(LC_CTYPE, old_locale);
		if (old_locale)free(old_locale);//还原区域设定
		file.Close();
		return 0;
	}
	return -1;
}
int CLogHelper::WriteLog9(LPCTSTR swzCur, LPCTSTR lpszLog)
{
	// 获取日志文件路径

	static CString strLogFilePath;
	strLogFilePath.Format(L"%s", swzCur);
	if (strLogFilePath.IsEmpty())
	{
		strLogFilePath = MakeFilePath();
	}
	// 判断日志文件是否存在，不存在则创建
	wchar_t* pwchLogFilePath = strLogFilePath.AllocSysString();
	errno_t err = 0;
	if ((err = _taccess_s(pwchLogFilePath, 0)) != 0)
	{
		CFile file;
		if (file.Open(strLogFilePath, CFile::modeCreate | CFile::typeBinary | CFile::modeWrite))
		{
			const unsigned char LeadBytes[] = { 0xEF, 0xBB, 0xBF };
			file.Write(LeadBytes, sizeof(LeadBytes));
			file.Close();
		}


	}
	SysFreeString(pwchLogFilePath);
	// 向日志文件写入日志
	CStdioFile file;
	if (file.Open((LPCTSTR)strLogFilePath, CFile::modeWrite | CFile::typeBinary | CFile::shareDenyNone))
		//	if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite ))
	{
		//  CString strMsg = MakeLogMsg(lpszLog);
		//CString strMsg = lpszLog;
		file.SeekToEnd();
		char* old_locale = _strdup(setlocale(LC_CTYPE, NULL));
		setlocale(LC_CTYPE, "chs");// 设定区域

		int nSrcLen = (int)wcslen(lpszLog);//content为要写入的文本
		CStringA utf8String(lpszLog);
		utf8String += L"\r\n";
		int nBufLen = (nSrcLen + 1) * 6;
		LPSTR buffer = utf8String.GetBufferSetLength(nBufLen);
		int nLen = AtlUnicodeToUTF8(lpszLog, nSrcLen, buffer, nBufLen);
		//上面的函数AtlUnicodeToUTF8()需头文件：<atlenc.h>
		//功能：将unicode转换成utf-8
		buffer[nLen] = 0;
		utf8String.ReleaseBuffer();

		file.Write(utf8String.GetBuffer(), nLen);

		setlocale(LC_CTYPE, old_locale);
		if (old_locale)free(old_locale);//还原区域设定
		file.Close();
		return 0;
	}
	return -1;
}
int CLogHelper::WriteLogSerial(LPCTSTR swzCur, LPCTSTR lpszLog)
{
	// 获取日志文件路径

	static CString strLogFilePath;
	strLogFilePath.Format(L"%s", swzCur);
	if (strLogFilePath.IsEmpty())
	{
		strLogFilePath = MakeFilePath();
	}
	// 判断日志文件是否存在，不存在则创建
	wchar_t* pwchLogFilePath = strLogFilePath.AllocSysString();
	errno_t err = 0;
	if ((err = _taccess_s(pwchLogFilePath, 0)) != 0)
	{
		CFile file;
		if (file.Open(strLogFilePath, CFile::modeCreate | CFile::typeBinary | CFile::modeWrite))
		{
			const unsigned char LeadBytes[] = { 0xEF, 0xBB, 0xBF };
			file.Write(LeadBytes, sizeof(LeadBytes));
			file.Close();
		}


	}
	SysFreeString(pwchLogFilePath);
	// 向日志文件写入日志
	CStdioFile file;
	if (file.Open((LPCTSTR)strLogFilePath, CFile::modeWrite | CFile::typeBinary | CFile::shareDenyNone))
		//	if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite ))
	{
		//  CString strMsg = MakeLogMsg(lpszLog);
		//CString strMsg = lpszLog;
		file.SeekToEnd();
		char* old_locale = _strdup(setlocale(LC_CTYPE, NULL));
		setlocale(LC_CTYPE, "chs");// 设定区域

		int nSrcLen = (int)wcslen(lpszLog);//content为要写入的文本
		CStringA utf8String(lpszLog);
		utf8String += L"\r\n";
		int nBufLen = (nSrcLen + 1) * 6;
		LPSTR buffer = utf8String.GetBufferSetLength(nBufLen);
		int nLen = AtlUnicodeToUTF8(lpszLog, nSrcLen, buffer, nBufLen);
		//上面的函数AtlUnicodeToUTF8()需头文件：<atlenc.h>
		//功能：将unicode转换成utf-8
		buffer[nLen] = 0;
		utf8String.ReleaseBuffer();

		file.Write(utf8String.GetBuffer(), nLen);

		setlocale(LC_CTYPE, old_locale);
		if (old_locale)free(old_locale);//还原区域设定
		file.Close();
		return 0;
	}
	return -1;
}

int CLogHelper::WriteKeyLog0(LPCTSTR swzCur, LPCTSTR lpszLog)
{
	// 获取日志文件路径

	static CString strLogFilePath;
	strLogFilePath.Format(L"%s", swzCur);
	if (strLogFilePath.IsEmpty())
	{
		strLogFilePath = MakeFilePath();
	}
	// 判断日志文件是否存在，不存在则创建
	wchar_t* pwchLogFilePath = strLogFilePath.AllocSysString();
	errno_t err = 0;
	if ((err = _taccess_s(pwchLogFilePath, 0)) != 0)
	{
		CStdioFile file;
		if (file.Open(strLogFilePath, CStdioFile::modeCreate))
		{
			file.Close();
		}
	}
	SysFreeString(pwchLogFilePath);
	// 向日志文件写入日志
	CStdioFile file;
	//  if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite | CStdioFile::shareDenyNone))
	if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite))
	{
		//  CString strMsg = MakeLogMsg(lpszLog);
		CString strMsg = lpszLog;
		file.SeekToEnd();
		char* old_locale = _strdup(setlocale(LC_CTYPE, NULL));
		setlocale(LC_CTYPE, "chs");// 设定区域
		file.WriteString(strMsg);
		setlocale(LC_CTYPE, old_locale);
		if(old_locale)free(old_locale);//还原区域设定
		file.Close();
		return 0;
	}
	return -1;
}
int CLogHelper::WriteKeyLog1(LPCTSTR swzCur, LPCTSTR lpszLog)
{
	// 获取日志文件路径

	static CString strLogFilePath;
	strLogFilePath.Format(L"%s", swzCur);
	if (strLogFilePath.IsEmpty())
	{
		strLogFilePath = MakeFilePath();
	}
	// 判断日志文件是否存在，不存在则创建
	wchar_t* pwchLogFilePath = strLogFilePath.AllocSysString();
	errno_t err = 0;
	if ((err = _taccess_s(pwchLogFilePath, 0)) != 0)
	{
		CStdioFile file;
		if (file.Open(strLogFilePath, CStdioFile::modeCreate))
		{
			file.Close();
		}
	}
	SysFreeString(pwchLogFilePath);
	// 向日志文件写入日志
	CStdioFile file;
	//  if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite | CStdioFile::shareDenyNone))
	if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite))
	{
		//  CString strMsg = MakeLogMsg(lpszLog);
		CString strMsg = lpszLog;
		file.SeekToEnd();
		char* old_locale = _strdup(setlocale(LC_CTYPE, NULL));
		setlocale(LC_CTYPE, "chs");// 设定区域
		file.WriteString(strMsg);
		setlocale(LC_CTYPE, old_locale);
		if(old_locale)free(old_locale);//还原区域设定
		file.Close();
		return 0;
	}
	return -1;
}
int CLogHelper::WriteKeyLog2(LPCTSTR swzCur, LPCTSTR lpszLog)
{
	// 获取日志文件路径

	static CString strLogFilePath;
	strLogFilePath.Format(L"%s", swzCur);
	if (strLogFilePath.IsEmpty())
	{
		strLogFilePath = MakeFilePath();
	}
	// 判断日志文件是否存在，不存在则创建
	wchar_t* pwchLogFilePath = strLogFilePath.AllocSysString();
	errno_t err = 0;
	if ((err = _taccess_s(pwchLogFilePath, 0)) != 0)
	{
		CStdioFile file;
		if (file.Open(strLogFilePath, CStdioFile::modeCreate))
		{
			file.Close();
		}
	}
	SysFreeString(pwchLogFilePath);
	// 向日志文件写入日志
	CStdioFile file;
	//  if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite | CStdioFile::shareDenyNone))
	if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite))
	{
		//  CString strMsg = MakeLogMsg(lpszLog);
		CString strMsg = lpszLog;
		file.SeekToEnd();
		char* old_locale = _strdup(setlocale(LC_CTYPE, NULL));
		setlocale(LC_CTYPE, "chs");// 设定区域
		file.WriteString(strMsg);
		setlocale(LC_CTYPE, old_locale);
		if(old_locale)free(old_locale);//还原区域设定
		file.Close();
		return 0;
	}
	return -1;
}
int CLogHelper::WriteKeyLog3(LPCTSTR swzCur, LPCTSTR lpszLog)
{
	// 获取日志文件路径

	static CString strLogFilePath;
	strLogFilePath.Format(L"%s", swzCur);
	if (strLogFilePath.IsEmpty())
	{
		strLogFilePath = MakeFilePath();
	}
	// 判断日志文件是否存在，不存在则创建
	wchar_t* pwchLogFilePath = strLogFilePath.AllocSysString();
	errno_t err = 0;
	if ((err = _taccess_s(pwchLogFilePath, 0)) != 0)
	{
		CStdioFile file;
		if (file.Open(strLogFilePath, CStdioFile::modeCreate))
		{
			file.Close();
		}
	}
	SysFreeString(pwchLogFilePath);
	// 向日志文件写入日志
	CStdioFile file;
	//  if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite | CStdioFile::shareDenyNone))
	if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite))
	{
		//  CString strMsg = MakeLogMsg(lpszLog);
		CString strMsg = lpszLog;
		file.SeekToEnd();
		char* old_locale = _strdup(setlocale(LC_CTYPE, NULL));
		setlocale(LC_CTYPE, "chs");// 设定区域
		file.WriteString(strMsg);
		setlocale(LC_CTYPE, old_locale);
		if(old_locale)free(old_locale);//还原区域设定
		file.Close();
		return 0;
	}
	return -1;
}
int CLogHelper::WriteKeyLog4(LPCTSTR swzCur, LPCTSTR lpszLog)
{
	// 获取日志文件路径

	static CString strLogFilePath;
	strLogFilePath.Format(L"%s", swzCur);
	if (strLogFilePath.IsEmpty())
	{
		strLogFilePath = MakeFilePath();
	}
	// 判断日志文件是否存在，不存在则创建
	wchar_t* pwchLogFilePath = strLogFilePath.AllocSysString();
	errno_t err = 0;
	if ((err = _taccess_s(pwchLogFilePath, 0)) != 0)
	{
		CStdioFile file;
		if (file.Open(strLogFilePath, CStdioFile::modeCreate))
		{
			file.Close();
		}
	}
	SysFreeString(pwchLogFilePath);
	// 向日志文件写入日志
	CStdioFile file;
	//  if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite | CStdioFile::shareDenyNone))
	if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite))
	{
		//  CString strMsg = MakeLogMsg(lpszLog);
		CString strMsg = lpszLog;
		file.SeekToEnd();
		char* old_locale = _strdup(setlocale(LC_CTYPE, NULL));
		setlocale(LC_CTYPE, "chs");// 设定区域
		file.WriteString(strMsg);
		setlocale(LC_CTYPE, old_locale);
		if(old_locale)free(old_locale);//还原区域设定
		file.Close();
		return 0;
	}
	return -1;
}
int CLogHelper::WriteKeyLog5(LPCTSTR swzCur, LPCTSTR lpszLog)
{
	// 获取日志文件路径

	static CString strLogFilePath;
	strLogFilePath.Format(L"%s", swzCur);
	if (strLogFilePath.IsEmpty())
	{
		strLogFilePath = MakeFilePath();
	}
	// 判断日志文件是否存在，不存在则创建
	wchar_t* pwchLogFilePath = strLogFilePath.AllocSysString();
	errno_t err = 0;
	if ((err = _taccess_s(pwchLogFilePath, 0)) != 0)
	{
		CStdioFile file;
		if (file.Open(strLogFilePath, CStdioFile::modeCreate))
		{
			file.Close();
		}
	}
	SysFreeString(pwchLogFilePath);
	// 向日志文件写入日志
	CStdioFile file;
	//  if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite | CStdioFile::shareDenyNone))
	if (file.Open((LPCTSTR)strLogFilePath, CStdioFile::modeWrite))
	{
		//  CString strMsg = MakeLogMsg(lpszLog);
		CString strMsg = lpszLog;
		file.SeekToEnd();
		char* old_locale = _strdup(setlocale(LC_CTYPE, NULL));
		setlocale(LC_CTYPE, "chs");// 设定区域
		file.WriteString(strMsg);
		setlocale(LC_CTYPE, old_locale);
		if(old_locale)free(old_locale);//还原区域设定
		file.Close();
		return 0;
	}
	return -1;
}
CString CLogHelper::MakeLogMsg(LPCTSTR lpszLog)
{
    CTime time = CTime::GetCurrentTime();
    CString strMsg = time.Format(L"[%Y-%m-%d %H:%M:%S] ");
    strMsg = strMsg + lpszLog + _T("\r\n");
    return strMsg;
}

CString CLogHelper::MakeFilePath()
{
    // 获取当前进程路径
    TCHAR szFilePath[MAX_PATH];
    memset(szFilePath, 0, MAX_PATH);
    ::GetModuleFileName(NULL, szFilePath, MAX_PATH);

    (_tcsrchr(szFilePath, _T('\\')))[1] = 0;//删除文件名，只获得路径字符串
    CString strFilePath = szFilePath;
	strFilePath = strFilePath ;
	
    return strFilePath;
}